/*
 * Copyright 2009 BioTeam Inc
 * 
 * Licensed under License GNU LESSER GENERAL PUBLIC LICENSE version 3.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.gnu.org/copyleft/lesser.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.bioteam.appweb.ws.client.program;

import java.lang.reflect.Method;

import junit.framework.TestCase;
import net.bioteam.appweb.TestConfig;
import net.bioteam.appweb.model.Program;
import net.bioteam.appweb.model.ProgramBuilder;
import net.bioteam.appweb.submit.ProgramValueBean;
import net.bioteam.appweb.user.User;
import net.bioteam.appweb.ws.WsClient;

public class EmbossPhylip extends TestCase
{

	public EmbossPhylip()
	{
		super();
	}
	public EmbossPhylip(String name)
	{
		super(name);
	}

	public WsClient client;
	protected void setUp() throws Exception
	{
		TestConfig.init();
		User user=new User();
		user.setName(TestConfig.username);
		user.setPassword(TestConfig.password);
		client=new WsClient(user, TestConfig.serviceURL, null);
	}
	public static void main(String args[]) throws Exception {
		EmbossPhylip test = new EmbossPhylip("testFtreedistpair");
		test.setUp();
		Method[] mss=test.getClass().getMethods();
		for (Method ms: mss)
		{
			if (ms.getName().startsWith("test"))
			{
				ms.invoke(test);
				//break;
			}
		}
		
		//EmbossPhylip test = new EmbossPhylip("testFtreedistpair");
		//junit.textui.TestRunner.run(test);
	}
	public void testFtreedistpair() throws Exception
	{
		String program="ftreedistpair";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("intreefile", "inputs/treedist1.dat");
		bean.setValue("bintreefile", "treedist1.dat");
		bean.setValue("outfile", "out.txt");
		bean.setValue("style", "s");
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFtreedist() throws Exception
	{
		String program="ftreedist";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("intreefile", "inputs/treedist.dat");
		bean.setValue("outfile", "out.txt");
		bean.setValue("dtype", "s");
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFrestml() throws Exception
	{
		String program="frestml";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("data", "inputs/restml.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFrestdist() throws Exception
	{
		String program="frestdist";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("data", "inputs/restdist.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFprotpars() throws Exception
	{
		String program="fprotpars";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("sequence", "inputs/protpars.dat");
		bean.setValue("njumble", "3");
		bean.setValue("seed", "3");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFprotdist() throws Exception
	{
		String program="fprotdist";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("sequence", "inputs/protdist.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFpromlk() throws Exception
	{
		String program="fpromlk";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("sequence", "inputs/proml.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFproml() throws Exception
	{
		String program="fproml";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("sequence", "inputs/proml.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFpenny() throws Exception
	{
		String program="fpenny";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("infile", "inputs/penny.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFpars() throws Exception
	{
		String program="fpars";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("infile", "inputs/pars.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFneighbor() throws Exception
	{
		String program="fneighbor";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("datafile", "inputs/neighbor.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFmix() throws Exception
	{
		String program="fmix";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("infile", "inputs/mix.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFkitsch() throws Exception
	{
		String program="fkitsch";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("datafile", "inputs/fkitsch.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFgendist() throws Exception
	{
		String program="fgendist";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("infile", "inputs/gendist.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFseqbootall() throws Exception
	{
		String program="fseqbootall";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("infilesequences", "inputs/seqboot.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFseqboot() throws Exception
	{
		String program="fseqboot";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("sequence", "inputs/seqboot.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFfitch() throws Exception
	{
		String program="ffitch";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("datafile", "inputs/fitch.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFfactor() throws Exception
	{
		String program="ffactor";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("infile", "inputs/factor.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFdrawtree() throws Exception
	{
		String program="fdrawtree";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("intreefile", "inputs/drawgram.tree");
		bean.setValue("previewer", "n");
		bean.setValue("plotter", "x");
		bean.setValue("plotfile", "out.bmp");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFdrawgram() throws Exception
	{
		String program="fdrawgram";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("intreefile", "inputs/drawgram.tree");
		bean.setValue("previewer", "n");
		bean.setValue("plotter", "x");
		bean.setValue("plotfile", "out.bmp");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFdolpenny() throws Exception
	{
		String program="fdolpenny";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("infile", "inputs/dolpenny.dat");
		
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFdollop() throws Exception
	{
		String program="fdollop";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("infile", "inputs/dollop.dat");
		
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFdnapenny() throws Exception
	{
		String program="fdnapenny";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("sequence", "inputs/dnapenny.dat");
		
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFdnapars() throws Exception
	{
		String program="fdnapars";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("sequence", "inputs/dnapars.dat");
		
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFdnamlk() throws Exception
	{
		String program="fdnamlk";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("sequence", "inputs/dnaml.dat");
		bean.setValue("printdata", "1");
		bean.setValue("ncategories", "2");
		bean.setValue("categories", "1111112222222");
		bean.setValue("rate", "'1.0 2.0'");
		bean.setValue("gamma", "h");
		bean.setValue("nhmmcategories", "5");
		bean.setValue("hmmrates", "'0.264 1.413 3.596 7.086 12.641'");
		bean.setValue("hmmprobabilities", "'0.522 0.399 0.076 0.0036 0.000023'");
		bean.setValue("lambda", "1.5");
		bean.setValue("weight", "0111111111110");
		//bean.setValue("lambda", "1.5");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFdnaml() throws Exception
	{
		String program="fdnaml";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("sequence", "inputs/dnaml.dat");
		bean.setValue("printdata", "1");
		bean.setValue("ncategories", "2");
		bean.setValue("categories", "1111112222222");
		bean.setValue("rate", "'1.0 2.0'");
		bean.setValue("gamma", "h");
		bean.setValue("nhmmcategories", "5");
		bean.setValue("hmmrates", "'0.264 1.413 3.596 7.086 12.641'");
		bean.setValue("hmmprobabilities", "'0.522 0.399 0.076 0.0036 0.000023'");
		bean.setValue("lambda", "1.5");
		bean.setValue("weight", "0111111111110");
		//bean.setValue("lambda", "1.5");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFdnainvar() throws Exception
	{
		String program="fdnainvar";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("sequence", "inputs/dnainvar.dat");
		bean.setValue("printdata", "1");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFdnadist() throws Exception
	{
		String program="fdnadist";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("sequence", "inputs/dnadist.dat");
		//bean.setValue("intreefile", "inputs/dnacomptree.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFdnacomp() throws Exception
	{
		String program="fdnacomp";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("sequence", "inputs/dnacomp.dat");
		bean.setValue("intreefile", "inputs/dnacomptree.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFdiscboot() throws Exception
	{
		String program="fdiscboot";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("infile", "inputs/discboot.dat");
		bean.setValue("seed", "3");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFcontrast() throws Exception
	{
		String program="fcontrast";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("infile", "inputs/contrast.dat");
		bean.setValue("intreefile", "inputs/contrast.tree");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFcontml() throws Exception
	{
		String program="fcontml";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("infile", "inputs/contml.dat");
		bean.setValue("printdata", "1");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFconsense() throws Exception
	{
		String program="fconsense";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean=new ProgramValueBean(p); if (TestConfig.clusterid!=null) 	{bean.setValue("_cluster", TestConfig.clusterid);}
		bean.setValue("intreefile", "inputs/consense.dat");
		bean.setValue("outfile", "out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}
	public void testFclique() throws Exception
	{
		String program="fclique";
		ProgramBuilder.cache.remove(program);
		Program p=ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		bean.setValue("infile", "inputs/clique.dat");
		bean.setValue("outfile", "clique_out.txt");
		
		String[] ret=client.runProgram(bean);
		postJobProcess(ret);
		
	}

	protected void postJobProcess(String ret[])
	{
		String jobid=ret[0];
		TestConfig.logger.info("job id is "+jobid);
		TestConfig.logger.info("cmdline is "+ret[2]);
	}
	
	

}
